package com.tjec.project.mobile.controller;

import com.tjec.common.constant.Constants;
import com.tjec.common.utils.SecurityUtils;
import com.tjec.common.utils.ServletUtils;
import com.tjec.common.utils.StringUtils;
import com.tjec.framework.security.LoginUser;
import com.tjec.framework.security.service.SysLoginService;
import com.tjec.framework.security.service.TokenService;
import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.framework.web.page.TableDataInfo;
import com.tjec.project.businessStandardLibrary.domain.BmsKnowledgeBusinessGuide;
import com.tjec.project.businessStandardLibrary.domain.BmsKnowledgeCase;
import com.tjec.project.businessStandardLibrary.domain.BmsKnowledgePolicies;
import com.tjec.project.mobile.service.MobileService;
import com.tjec.project.portal.domain.BmsMsg;
import com.tjec.project.portal.domain.BmsNotes;
import com.tjec.project.projectLeaderWorkbeanch.domain.BmsExpertPerson;
import com.tjec.project.projectLeaderWorkbeanch.domain.BmsLeaderMember;
import com.tjec.project.projectWorkbench.domain.BmsProject;
import com.tjec.project.projectWorkbench.domain.BmsProjectFocus;
import com.tjec.project.projectWorkbench.service.IBmsProjectFocusService;
import com.tjec.project.projectWorkbench.service.IBmsProjectService;
import com.tjec.project.system.domain.SysMenu;
import com.tjec.project.system.domain.SysUser;
import com.tjec.project.system.domain.vo.RouterVo;
import com.tjec.project.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * 移动端主页controller类
 *
 * @author ：cjj
 * @date ：Created in 2020/8/17 11:38
 */
@Api(value = "移动端主页接口" , tags = {"移动端主页接口"})
@RestController
@RequestMapping("/mobile/portal")
public class PortalController extends BaseController{

    @Autowired
    private IBmsProjectService bmsProjectService;

    @Autowired
    private MobileService mobileService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private IBmsProjectFocusService bmsProjectFocusService;

    /**
     * 我的项目
     */
    @ApiOperation("我的项目")
    @GetMapping("/myProject")
    public AjaxResult myProject(){
        return AjaxResult.success(bmsProjectService.countMyProject(SecurityUtils.getLoginUser().getUser().getUserId()));
    }

    /**
     * 我的消息
     */
    @ApiOperation("我的消息")
    @GetMapping("/myMessageList")
    public TableDataInfo myMessageList(BmsMsg bmsMsg){
        startPage();
        List<BmsMsg> list = mobileService.selectBmsMsgMobileList(bmsMsg);
        return getDataTable(list);
    }

    /**
     * 我的消息-一键已读
     */
    /*@ApiOperation("我的消息-一键已读")
    @GetMapping("/myMessageBatchRead")
    public AjaxResult myMessageBatchRead(){
        int result = mobileService.myMessageBatchRead();
        return toAjax(result);
    }*/

    /**
     * 我的便签
     */
    @ApiOperation("我的便签")
    @GetMapping("/myNoteList")
    public TableDataInfo myNoteList(BmsNotes bmsNotes){
        startPage();
        List<BmsNotes> list = mobileService.selectBmsNotesMobileList(bmsNotes);
        return getDataTable(list);
    }

    /**
     * 业务手册
     */
    @ApiOperation("业务手册")
    @GetMapping("/businessManualList")
    public TableDataInfo businessManualList(BmsKnowledgeBusinessGuide bmsKnowledgeBusinessGuide){
        startPage();
        List<BmsKnowledgeBusinessGuide> list = mobileService.selectBmsKnowledgeBusinessGuideMobileList(bmsKnowledgeBusinessGuide);
        return getDataTable(list);
    }

    /**
     * 典型案例
     */
    @ApiOperation("典型案例")
    @GetMapping("/typicalCaseList")
    public TableDataInfo typicalCaseList(BmsKnowledgeCase bmsKnowledgeCase){
        startPage();
        List<BmsKnowledgeCase> list = mobileService.selectBmsKnowledgeCaseMobileList(bmsKnowledgeCase);
        return getDataTable(list);
    }

    /**
     * 法规导航
     */
   /* @ApiOperation("法规导航")
    @GetMapping("/ruleNavigationList")
    public TableDataInfo ruleNavigationList(BmsKnowledgePolicies bmsKnowledgePolicies){
        startPage();
        List<BmsKnowledgeCase> list = mobileService.selectBmsKnowledgePoliciesMobileList(bmsKnowledgePolicies);
        return getDataTable(list);
    }*/

    /**
     * 项目清单
     */
    @ApiOperation("项目清单")
    @GetMapping("/projectList")
    public TableDataInfo projectList(BmsProject bmsProject){
        String projectLeaderNo = sysUserService.findProjectLeaderNoByUserGuid(bmsProject.getProjectLeader());

        if(StringUtils.isNotBlank(projectLeaderNo)){
            bmsProject.setProjectLeaderNo(projectLeaderNo);
            bmsProject.setProjectLeader("");
        }
        startPage();
        //负责人工作台不显示"作废"项目，不显示“冻结”项目
        bmsProject.setIsvalid("1");
        bmsProject.setFreezeStatus("1");
        List<BmsProject> list = mobileService.selectBmsProjectMobileList(bmsProject);
        return getDataTable(list);
    }

    /**
     * 人员清单
     */
    @ApiOperation("人员清单")
    @GetMapping("/personnelList")
    public TableDataInfo projectList(BmsLeaderMember bmsLeaderMember){
        startPage();
        List<BmsLeaderMember> list = mobileService.selectBmsLeaderMemberMobileList(bmsLeaderMember);
        return getDataTable(list);
    }

    /**
     * 人员清单
     */
    @ApiOperation("专家清单")
    @GetMapping("/expertList")
    public TableDataInfo expertList(BmsExpertPerson bmsExpertPerson){
        startPage();
        List<BmsExpertPerson> list = mobileService.selectBmsExpertPersonMobileList(bmsExpertPerson);
        return getDataTable(list);
    }

    /**
     * 项目工作台
     */
    @ApiOperation("项目工作台")
    @GetMapping("/projectWorkbenchList")
    public TableDataInfo projectWorkbenchList(BmsProject bmsProject){
        String currentUserId = SecurityUtils.getLoginUser().getUser().getUserId();
        bmsProject.setUserId(currentUserId);
        String projectLeaderNo = sysUserService.findProjectLeaderNoByUserGuid(bmsProject.getUserId());
        if(StringUtils.isNotBlank(projectLeaderNo)){
            bmsProject.setProjectLeaderNo(projectLeaderNo);
        }
        startPage();
        //项目工作台不显示"作废"项目，不显示“冻结”项目
        bmsProject.setIsvalid("1");
        bmsProject.setFreezeStatus("1");
        List<BmsProject> list = mobileService.selectBmsProjectGlanceMobileList(bmsProject);
        return getDataTable(list);
    }

/*    *//**
     * 是否为项目负责人或项目负责人工作台管理员
     *//*
    @ApiOperation("是否为项目负责人或项目负责人工作台管理员")
    @GetMapping("/isProjectLeader")
    public AjaxResult isProjectLeader(){
        AjaxResult ajaxResult = new AjaxResult();
        String currentUserId = SecurityUtils.getLoginUser().getUser().getUserId();
        ajaxResult.put("isProjectLeader", mobileService.isProjectLeader(currentUserId));
        return ajaxResult;
    }*/

    /**
     * 项目负责人下拉列表
     */
    @ApiOperation("项目负责人下拉列表")
//    @PreAuthorize("@ss.hasPermi('projectLeader:personalExpert:leaderList')")
    @GetMapping("/leaderList")
    public AjaxResult leaderList(BmsLeaderMember bmsLeaderMember)
    {
        if(bmsLeaderMember.getUserId() == null){
            bmsLeaderMember.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        }
        bmsLeaderMember.setRole("1");
        List<BmsLeaderMember> list = mobileService.selectBmsLeaderMemberList(bmsLeaderMember);
        return AjaxResult.success(list);
    }

    /**
     * 首页-我关注的项目
     * liuxu
     */
    @ApiOperation("首页-我关注的项目")
    @GetMapping("/focusProject")
    public AjaxResult focusProject() {
        BmsProjectFocus bmsProjectFocus = new BmsProjectFocus();
        bmsProjectFocus.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        return AjaxResult.success(bmsProjectFocusService.selectBmsProjectFocusList(bmsProjectFocus));
    }
}
